package com.baizhi.service.impl;

import com.baizhi.dao.ArticleDAO;
import com.baizhi.entity.Article;
import com.baizhi.service.ArticleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleDAO articleDAO;
    @Override
    public PageInfo<Article> selectAllArticle(String name, Integer page, Integer limit) {
        //  设置分页起始条数
        PageHelper.startPage(page,limit);
        List<Article> articles = articleDAO.selectAllArticle(name);
        PageInfo<Article> pageInfo = new PageInfo<>(articles);
        return pageInfo;
    }

    @Override
    public Boolean insertArticle(Article article) {
        Boolean a = null;
        try {
            articleDAO.insertArticle(article);
            a = true;
        }catch(Exception e){
            a = false;
        }
        return a;
    }

    @Override
    public Boolean updateArticle(Article article) {
        Boolean a = null;
        try {
            articleDAO.updateArticle(article);
            a = true;
        }catch(Exception e){
            a = false;
        }
        return a;
    }

    @Override
    public Article selectOneArticle(Integer id) {
        Article article = articleDAO.selectOneArticle(id);
        return article;
    }

    @Override
    public Boolean deleteArticle(Integer id) {
        Boolean a = null;
        try {
            articleDAO.deleteArticle(id);
            a = true;
        }catch(Exception e){
            a = false;
        }
        return a;
    }

    @Override
    public Boolean updateGid(Article article) {
        Boolean a = null;
        try {
            articleDAO.updateGid(article);
            a = true;
        }catch(Exception e){
            a = false;
        }
        return a;
    }
}
